/**
 * Created by yezhimeih7 on 2016/12/16.
 * mail: yezhimeih7@foxmail.com
 * url: http://www.tcioc.com
 * 后台文件上传的相关js操作
 */
;(function($){
    /*删除文件*/
    $("button.btn-file-delete").click(function(){
        var url=$(this).attr("data-url"),
            id= $(this).parent().find('input[name="id"]').val(),
            that=this;
        $(this).parent().find("span").remove();
        $.get(url,"",function(msg){
            if(msg.status==1){
                $(that).before('<span class="bg-success">'+msg.info+' &emsp;</span>');
                setInterval(function(){
                    $("#myModal_"+id).modal("hide");
                    reloadPage(window);
                },1500);
            }else{
                $(that).before('<span class="bg-warning">'+msg.info+' &emsp;</span>');
            }
        });
    });
    /*每次关闭 model层，都需要刷新页面,需要引入common.js */
    $('#upload_plane_modal').on('hidden.bs.modal', function (e) {
        reloadPage(window);
    });
    /*保存文件信息*/
    $('.btn-file-save').click(function(){
        var url=$(this).attr("data-url"),
            id= $(this).parent().find('input[name="id"]').val(),
            that=$(this).parent().find("button.btn-file-delete");
        $(this).parent().find("span").remove();
        $.post(url,{
            id:id,
            name:$("input#name_"+id).val(),
            title:$("input#title_"+id).val(),
            desc:$("textarea#desc_"+id).val(),
            uri:$("input#link_"+id).val(),
        },function(msg){
            if(msg.status==1){
                $(that).before('<span class="bg-success">'+msg.info+' &emsp;</span>');
                setInterval(function(){
                    $("#myModal_"+id).modal("hide");
                    reloadPage(window);
                },1500);
            }else{
                $(that).before('<span class="bg-warning">'+msg.info+' &emsp;</span>');
            }
        });
    });
})(jQuery);
